<template>
  <div class="singerAlbumsList">
    <el-empty
      v-if="albumList.length === 0"
      description="正在加载专辑~"
    ></el-empty>
    <div v-else>
      <div class="content">
        <div class="content_item" v-for="item in albumList" :key="item.id">
          <div class="content_item_img">
            <GlobalImageDeep
              :url="item.picUrl"
              :imgWidth="224"
              :imgHeight="224"
            />
            <!-- 播放按钮 -->
            <GlobalPlayMask
              :maskWidth="64"
              :maskHeight="64"
              @maskClick="toAlbumDetailsPage(item.id)"
            />
          </div>
          <p class="one_txt_cut">{{ item.name }}</p>
          <i class="one_txt_cut"> {{ formatPublishTime(item.publishTime) }}</i>
        </div>
      </div>
      <!-- 分页 -->
      <el-row
        type="flex"
        class="row-bg"
        justify="center"
        v-if="albumList.length !== 0"
      >
        <el-pagination
          layout="prev, pager, next"
          :total="total"
          :page-size="12"
          @current-change="paginationCurrentChange"
          :current-page="currentPage"
        >
        </el-pagination>
      </el-row>
    </div>
  </div>
</template>

<script>
import { getSingerAllAlbums } from "../../../../../api/singerDetailsApi";
import moment from "moment";
export default {
  name: "singerAlbumsList",
  components: {},
  props: {
    id: {
      required: true,
      type: Number,
    },
    total: {
      required: true,
      type: Number,
    },
  },
  data() {
    return {
      albumList: [],
      queryInfo: {
        id: 0,
        limit: 12,
        offset: 0,
      },
      currentPage: 1,
    };
  },
  created() {
    // console.log("正在加载专辑页面");
    this.queryInfo.id = this.id;
    this.getSingerAllAlbumsMthod();
  },
  methods: {
    async getSingerAllAlbumsMthod() {
      let result = await getSingerAllAlbums(this.queryInfo);
      if (result.code === 200) {
        this.albumList = result.hotAlbums;
      }
    },
    paginationCurrentChange(newPage) {
      this.queryInfo.offset = (newPage - 1) * this.queryInfo.limit;
      this.currentPage = newPage;
      // this.$utils.scrollTop(0, 200);
      this.getSingerAllAlbumsMthod();
      // console.log(document.querySelector(".singerAlbumsList").offsetTop);
    },
    // 格式化 发布时间
    formatPublishTime(time) {
      return moment(time).format("YYYY-MM-DD");
    },
    toAlbumDetailsPage(id) {
      this.$router.push(`/albumDetails/${id}`);
    },
  },
  computed: {},
  watch: {
    id: {
      // deep: true,
      handler(newValue) {
        // console.log("获取到的最新的id", newValue);
        this.queryInfo.id = newValue;
        this.queryInfo.offset = 0;
        this.currentPage = 1;
        this.getSingerAllAlbumsMthod();
      },
    },
    total(newValue) {
      this.total = newValue;
    },
  },
};
</script>

<style lang="less" scoped>
.singerAlbumsList {
  /deep/ .el-pager li.active {
    color: #fff;
    background: @globalColor;
    border-radius: 50%;
    &:hover {
      color: #fff;
    }
  }
  /deep/ .el-pager li:hover {
    color: @globalColor;
  }

  /deep/ .el-image img {
    border-radius: 8px !important;
  }
  .content {
    display: flex;
    justify-content: space-between;
    flex-wrap: wrap;
    .content_item {
      height: 316px;
      width: 288px;
      font-size: 14px;

      &:hover {
        /deep/ .playMask .play {
          display: block;
          cursor: pointer;
        }
      }

      .content_item_img {
        position: relative;
        width: 224px;
        height: 224px;
        &::before {
          content: "";
          position: absolute;
          top: 0;
          left: 30px;
          width: 100%;
          height: 100%;
          background: url("../../../../../assets/images/album-cover-gold.png")
            no-repeat center;
        }
      }
      p {
        width: 224px;
        color: #333333;
        margin-top: 10px;
        margin-bottom: 10px;
        &:hover {
          color: @globalColor;
          // animation: bounce 1s;
          cursor: pointer;
        }
      }
      i {
        width: 224px;
        display: block;
        color: #999999;
        &:hover {
          // color: @globalColor;
          // animation: bounce 1s;
          cursor: pointer;
        }
      }
    }
  }
}
</style>
